<template>
	<view class="wapper">
		<view class="form-con">
			<view class="item-list-none">
				<view class="name">
					<text class="red">
						*
					</text> 驳回原因
				</view>
			</view>
			<view class="text-area">
				<textarea v-model="remark" placeholder="请输入"></textarea>
			</view>
		</view>
		<view class="footer" @click="handleConfirm">
			提交
		</view>
		<u-modal :show="showConfirm" @cancel="showConfirm=false" @confirm="newSubmit" :showCancelButton="true"
			title="提示" content='是否确认提交?'></u-modal>
	</view>
</template>

<script>
	import {
		approveWorkOrder,
	} from '@/api/maintain.js'
	import {
		approveWorkOrderRepair
	} from '@/api/repair.js'
	import {
		approvePurchase
	} from '@/api/purchase.js'
	import {
		approveRequisition
	} from '@/api/requisition.js'
	export default {
		data() {
			return {
				id: '',
				type: '', // 1保养工单,2维修工单，3：领用 4:请购
				remark: '',
				showConfirm: false,
			}
		},
		onLoad(option) {
			this.id = option.id || ''
			this.type = option.type || ''
		},
		onShow() {

		},
		created() {

		},
		methods: {
			handleConfirm() {
				if (!this.remark) {
					uni.showToast({
						icon: 'none',
						title: '请输入驳回原因',
						duration: 3000,
					})
					return
				}
				this.showConfirm = true
				if (this.showConfirm) {
					return
				}

			},
			newSubmit() {
				this.showConfirm = false
				const paramData = {
					id: this.id,
					approvalResult: 2,
					remark: this.remark
				}
				uni.showLoading({
					mask: true,
					title: '加载中',
				})
				if (this.type === '1') {
					approveWorkOrder(paramData).then(response => {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							mask: true,
							duration: 2000,
						})
						setTimeout(() => {
							uni.hideLoading()
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
						// this.$emit('getDetail')
					}).finally(() => {
					})
				}
				if (this.type === '2') {
					approveWorkOrderRepair(paramData).then(response => {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							duration: 2000,
							mask: true,
						})
						setTimeout(() => {
							uni.hideLoading()
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
						// this.$emit('getDetail')
					}).finally(() => {
					})
				}
				if (this.type === '3') {

					approveRequisition(paramData).then(response => {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							mask: true,
							duration: 2000,
						})
						setTimeout(() => {
							uni.hideLoading()
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
					}).finally(() => {
					})
				}


				if (this.type === '4') {

					approvePurchase(paramData).then(response => {

						uni.showToast({
							icon: 'none',
							title: '提交成功',
							mask: true,
							duration: 2000,
						})
						setTimeout(() => {
								uni.hideLoading()
							uni.navigateBack({
								delta: 1
							})
						}, 2000)
					}).finally(() => {
					
					})
				}

			}

		}
	}
</script>

<style lang="scss" scoped>
	.wapper {
		width: 100vw;
		min-height: calc(100vh - 160rpx);
		background: #F5F7F9;
		overflow: hidden;
		// padding-bottom: 104rpx;


		.form-con {
			margin-top: 10rpx;
			background: #fff;
			height: calc(100vh - 300 rpx);

			.item-list-none {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx;

				.name {
					font-size: 32rpx;
					font-weight: 400;

					.red {
						color: #FF654E;
					}
				}

			}



			.text-area {
				margin: 0 30rpx;

				textarea {
					width: 100%;
				}
			}

		}

		.footer {
			width: 686rpx;
			height: 104rpx;
			background: #407FFF;
			border-radius: 52rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			// position: fixed;
			// bottom: 118rpx;
			// left: 38rpx;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			margin: 38rpx auto;

		}
	}
</style>
